let Http = require('../../models/douban.js');
Page({

   /**
    * 页面的初始数据
    */
   data: {
      movie:{},
      type:[],
      casts:[],
      directors:[],
      scrollLeft:0
   },

   /**
    * 生命周期函数--监听页面加载
    */
   onLoad:async function (options) {
      let {id} = options;
      let casts = [];
      let directors = [];
      let detail = {};
      detail = wx.getStorageSync('detail');
      if(id in detail){
         this.setData({
            movie:detail[id],
            type:detail[id].genres
         });
         this.data.movie.casts.forEach(item=>{
            casts.push(item.name);
         });
         this.data.movie.directors.forEach(item=>{
            directors.push(item.name)
         });
         this.setData({
            directors,
            casts,
         });
      }else{
         let res = await Http.getDetail(id);
         this.setData({
            movie:res,
            type:res.genres
         });
         this.data.movie.casts.forEach(item=>{
            casts.push(item.name);
         });
         this.data.movie.directors.forEach(item=>{
            directors.push(item.name)
         });
         this.setData({
            directors,
            casts,
         });
         let movie = this.data.movie;
         detail[id] = movie;
         wx.setStorageSync('detail', detail);
      }
   },

})